package com.suxin.opentsdb.config;

import org.apache.http.nio.reactor.IOReactorException;
import org.opentsdb.client.OpenTSDBClient;
import org.opentsdb.client.OpenTSDBClientFactory;
import org.opentsdb.client.OpenTSDBConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname OpenTsdbConfig
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/10/14 9:58
 * @Created by ASUS
 */
@Configuration
public class OpenTsdbConfig {

    @Bean
    public OpenTSDBClient getClient() throws IOReactorException {

        OpenTSDBConfig openTSDBConfig = OpenTSDBConfig.address("http://192.168.108.128", 4242)
                // http连接池大小，默认100
                .httpConnectionPool(100)
                // http请求超时时间，默认100s
                .httpConnectTimeout(100)
                // 异步写入数据时，每次http提交的数据条数，默认50
                .batchPutSize(50)
                // 异步写入数据中，内部有一个队列，默认队列大小20000
                .batchPutBufferSize(20000)
                // 异步写入等待时间，如果距离上一次请求超多300ms，且有数据，则直接提交
                .batchPutTimeLimit(300)
//                // 当确认这个client只用于查询时设置，可不创建内部队列从而提高效率
//                .readonly()
                .config();
        return OpenTSDBClientFactory.connect(openTSDBConfig);
    }

}